<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive,defineProps,onMounted } from 'vue'
import financialSettleDetail from '@/api/financial/financialSettleDetail'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
import { before } from 'lodash'

const crudRef = ref()
const props = defineProps({
  itemData:Object
})
onMounted(()=>{
  crudRef.value.requestData()
})

const options = reactive({
  id: 'flyos_financial_settle_detail',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  searchColNumber:6,
  operationColumn: false,
  operationWidth: 160,
  autoRequest:false,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: financialSettleDetail.getList,
  recycleApi: financialSettleDetail.getRecycleList,
  add: {
    show: false,
    api: financialSettleDetail.save,
    auth: ['financial:settleDetail:save']
  },
  edit: {
    show: false,
    api: financialSettleDetail.update,
    auth: ['financial:settleDetail:update']
  },
  delete: {
    show: false,
    api: financialSettleDetail.deletes,
    auth: ['financial:settleDetail:delete'],
    realApi: financialSettleDetail.realDeletes,
    realAuth: ['financial:settleDetail:realDeletes']
  },
  recovery: {
    show: false,
    api: financialSettleDetail.recoverys,
    auth: ['financial:settleDetail:recovery']
  },
  import: {
    show: false,
    url: 'financial/settleDetail/import',
    templateUrl: 'financial/settleDetail/downloadTemplate',
    auth: ['financial:settleDetail:import']
  },
  export: {
    show: false,
    url: 'financial/settleDetail/export',
    auth: ['financial:settleDetail:export']
  },
  beforeRequest:(params)=>{
    params.settle_id = props.itemData.id
  },
  afterRequest:(params)=>{
    params.map((v,i)=>{
      if(!v.cost_detail.prediction){
        v.cost_detail.prediction = v.cost_detail.send
      }
      v.yundanhao = v.cost_detail.prediction.yundanhao
      v.dept_id = v.cost_detail.dept_id
      v.ticket_number = v.cost_detail.prediction.ticket_number
      v.car_no = v.cost_detail.prediction.car_no
      v.box = v.cost_detail.prediction.box
      v.goods_name = v.cost_detail.prediction.goods_name
      v.number = v.cost_detail.prediction.number
      v.process_time = v.cost_detail.prediction.process_time
    })
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "运单号",
    dataIndex: "yundanhao",
    search: true,
    formType: "input",
  },
  {
    title: "客户",
    dataIndex: "dept_id",
    formType: "select",
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          type: ["=", 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [],
      },
      translation: true
    },
  },
  {
    title: "原票号",
    dataIndex: "ticket_number",
    
    formType: "input",
  },
  {
    title: "车号",
    dataIndex: "car_no",
    formType: "input",
  },
  {
    title: "集装箱",
    dataIndex: "box",
    formType: "input",
  },
  {
    title: "品名",
    dataIndex: "goods_name",
    formType: "input",
  },
  {
    title: "件数",
    dataIndex: "number",
    formType: "input",
  },
  {
    title: "货重",
    dataIndex: "hz_weight",
    formType: "input",
  },
  {
    title: "税额",
    dataIndex: "tax_price",
    formType: "input",
    search: true
  },
  {
    title: "不含税价",
    dataIndex: "no_tax_price",
    formType: "input",
    search: true
  },
  {
    title: "含税价",
    dataIndex: "price",
    formType: "input",
    search: true
  },
  {
    title: "办理时间",
    dataIndex: "process_time",
    formType: "range",
    addDisplay: false,
    editDisplay: false,
    search: true,
    showTime: true
  },
  {
    title: "修改时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'financial:settleDetail' } </script>